﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VMind.Global;

namespace PPIDesktopClient.Controls.Position
{
    public partial class Position : UserControl
    {
        public Position()
        {
            InitializeComponent();
        }

        public double GetAltitude()
        {
            return  ConvertHelper.Todouble(txtAltitude.Text);    
        }
        public double GetLatitude()
        {
            return ConvertHelper.Todouble(txtLatitude.Text);
        }
        public double GetLongitude()
        {
            return ConvertHelper.Todouble(txtLongitude.Text);
        }
        public DateTime GetSatelliteTime()
        {
            return dateSatelliteTime.Value;
        }
        public int GetSatelliteCount()
        {
            return txtSatelliteCount.Value;
        }

        public void SetAltitude(double altitude)
        {
            if (altitude != double.MinValue)
                this.txtAltitude.Text = altitude.ToString();
            else
                this.txtAltitude.Clear();
        }
        public void SetLatitude(double latitude)
        {
            if (latitude != double.MinValue)
                this.txtLatitude.Text = latitude.ToString();
            else
                this.txtLatitude.Clear();
        }
        public void SetLongitude(double longitude)
        {
            if (longitude != double.MinValue)
                this.txtLongitude.Text = longitude.ToString();
            else
                this.txtLongitude.Clear();
        }
        public void SetSatelliteTime(DateTime satelliteTime)
        {
            this.dateSatelliteTime.Value = satelliteTime;
        }
        public void SetSatelliteCount(int satelliteCount)
        {
            if (satelliteCount != int.MinValue)
                this.txtSatelliteCount.Value = satelliteCount;
            else
                this.txtSatelliteCount.Value = 0;
        }

        public void CleanPositions()
        {
            txtAltitude.Clear();
            txtLatitude.Clear();
            txtLongitude.Clear();
            txtSatelliteCount.Value = 0;
            dateSatelliteTime.Value = DateTime.MinValue;
        }

        public bool ValidatePosition()
        {
            bool _Validate = true;
            if (GetSatelliteCount() == 0)
                _Validate = false;
            if(GetAltitude() == double.MinValue)
                _Validate = false;
            if (GetLongitude() == double.MinValue)
                _Validate = false;
            if (GetSatelliteTime() == DateTime.MinValue)
                _Validate = false;
            lblError.Visible = !_Validate;
            return _Validate;
        }
    }
}
